//
//  People.m
//  DebugDemo
//
//  Created by XFB on 2018/11/12.
//  Copyright © 2018年 ZhouCheng. All rights reserved.
//

#import "People.h"

@implementation People

+ (instancetype)people
{
    People *people = [[People alloc] init];
    people->_name = @"_name";
    people->_isName = @"_isName";
//    people->name = @"name";
    people->isName = @"isName";
    
    /**
     1、先搜方法 －>accessInstanceVariablesDirectly(YES) -> 再搜变量;
     2、先搜方法 －>accessInstanceVariablesDirectly(NO) -> 结束;
     */
    
    return people;
}

/// 1.
- (NSString *)getName
{
    NSLog(@"%s",__func__);
    return @"func getName";
}

/// 2.
- (NSString *)name
{
    NSLog(@"%s",__func__);
    return @"func name";
}

/// 3.
- (NSString *)isName
{
    NSLog(@"%s",__func__);
    return @"func isName";
}

/// 此方法决定是否可以通过KVC获取私有变量--默认是YES
+ (BOOL)accessInstanceVariablesDirectly
{
    return YES;
}

/// 容错处理
- (void)setValue:(id)value forUndefinedKey:(NSString *)key
{
    NSLog(@"accessInstanceVariablesDirectly 为 NO");
}

/// 重新valueForUndefined方法，解决崩溃的问题
- (id)valueForUndefinedKey:(NSString *)key
{
    return nil;
}

- (void)setNilValueForKey:(NSString *)key
{
    NSLog(@"不能将%@设成nil",key);
}


- (instancetype)peopleModelWithDict:(NSDictionary *)dict
{
    People *people = [[People alloc] init];
    [people setValuesForKeysWithDictionary:dict];
    return people;
}


- (void)setValue:(id)value forKey:(NSString *)key
{
    if ([key isEqualToString:@"id"]) {
        [super setValue:value forKey:@"personID"];
    }
}

@end
